package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.bean.WormBean;
import com.project.dao.WormDao;
import com.project.service.WormService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 病害
 */

@Service
@Transactional
public class WormServiceImpl extends ServiceImpl<WormDao, WormBean> implements WormService {
    @Override
    public IPage<WormBean> findAllWorm(int pageNo, int pageSize) {
        Page<WormBean> page = new Page<>(pageNo,pageSize);
        IPage<WormBean> iPage = this.page(page);
        return iPage;
    }

    @Override
    public void addWorm(WormBean worm) {
//        this.baseMapper.addWorm(worm);
        this.save(worm);

    }

    @Override
    public WormBean findId(int wormId) {
        return this.baseMapper.findId(wormId);
    }

    @Override
    public IPage<WormBean> findName(int pageNo, int pageSize,
                                    String wormName, String wormSp) {
        Page<WormBean> page = new Page<>(pageNo,pageSize);
        QueryWrapper wrapper = new QueryWrapper();
        if (wormName!=null && !wormName.equals("")){
            wrapper.like("f_wormName",wormName);
        }
        if (wormSp!=null && !wormSp.equals("")){
            wrapper.like("f_wormSp",wormSp);
        }
        IPage<WormBean> iPage = this.page(page,wrapper);
        return iPage;
    }
}
